package com.shangyitong.yygh_cmn.controller;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mysql.jdbc.log.Log;
import com.shangyitong.Result;

import com.shangyitong.yygh.model.cmn.Dict;
import com.shangyitong.yygh_cmn.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("数据字典接口")
@RestController
@Slf4j
@RequestMapping("admin/cmn/dict")
public class DictContoller {
    @Autowired
    private DictService dictService;
    /**
     * 根据数据id获取子数据列表
     * finished
     * @param id
     * @return
     */
    @ApiOperation(value = "根据数据id获取子数据列表")
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id){
        List<Dict> childData = dictService.findChildData(id);
        return Result.ok(childData);
    }

    /**
     * 导出excel数据
     * finished
     * @param response
     * @return
     */
    @ApiOperation(value="导出")
    @GetMapping(value = "exportData")
    public void exportData(HttpServletResponse response){
        dictService.exportData(response);
    }

    /**
     * 导入excel数据
     * finished
     * @param file
     * @return
     */
    @ApiOperation(value = "导入")
    @PostMapping("importData")
    public Result importData(MultipartFile file){
        dictService.importData(file);
        //返回数据
        return Result.ok();
    }

    /**
     * 根据dictCode,value获取医院级别名称
     * finished
     * @param dictCode
     * @param value
     * @return
     */
    @ApiOperation(value = "获取数据字典名称")
    @GetMapping("/getName/{dictCode}/{value}")
    public String getName(@PathVariable String dictCode,
                          @PathVariable String value){
        return dictService.getName(dictCode, value);
    }

    /**
     * finished
     * @param value
     * @return
     */
    @ApiOperation(value = "获取单个数据字典名称")
    @GetMapping("/getSingleName/{value}")
    public String getSingleName(@PathVariable String value){
        return this.getName("", value);
    }
    /**
     * 根据dictcode查询所有子节点
     * finished
     * @param dictCode
     * @return
     */
    @ApiOperation("根据dictcode查询所有子节点")
    @GetMapping("findByDictCode/{dictCode}")
    public Result findByDictCode(@PathVariable String dictCode){
        List<Dict> dicts = dictService.findByDictCode(dictCode);
        return Result.ok(dicts);
    }

}
